import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        theme: ThemeData(
          useMaterial3: false,
          primarySwatch: Colors.blue,
        ),
        home: Scaffold(
          appBar: AppBar(
            title: const Text("Flutter App"),
          ),
          body: const MyHome(),
        )
    );
  }
}

class MyHome extends StatefulWidget {
  const MyHome({super.key});

  @override
  State<MyHome> createState() => _MyHomeState();
}

class _MyHomeState extends State<MyHome> {
  //设置groupValue,每一组radio都必须设置一个
  int? _gender;
  int? _subject;

  @override
  void initState() {
    super.initState();

  }

  @override
  void dispose() {
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Center(
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          const Text("性别",style: TextStyle(fontSize: 16),),
          Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Radio(value: 1, groupValue: _gender, onChanged: (value){
                setState(() {
                  _gender = value;
                });
              }),
              const Text("男")
            ],
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Radio(value: 0, groupValue: _gender, onChanged: (value){
                setState(() {
                  _gender = value;
                });
              }),
              const Text("女")
            ],
          ),

          const Text("科目",style: TextStyle(fontSize: 16),),
          RadioListTile(
              title: const Text("数学") ,
              value: 0,
              groupValue: _subject,
              onChanged: (value){
                setState(() {
                  _subject = value;
                });
              }
          ),
          RadioListTile(
              title: const Text("英语") ,
              value: 1,
              groupValue: _subject,
              onChanged: (value){
                setState(() {
                  _subject = value;
                });
              }
          ),
          RadioListTile(
              title: const Text("语文") ,
              value: 2,
              groupValue: _subject,
              onChanged: (value){
                setState(() {
                  _subject = value;
                });
              }
          ),
        ],
      ),
    );
  }
}
